// pages/supplement/index.js
const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    oids:[],
    payData: [],
    orderNumList:[],
    orderIdList:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  pay: function () {
    this.setData({
      showModal: true
    })
  },

  hideModal: function () {
    this.setData({
      showModal: false
    });
  },

  getPayData(){
    let that=this;
    wx.request({
      url: app.globalData.basicUrl + 'user/userOrder/selectUserOrderUnpayList',
      //selectUserOrderUnpayList
      method:'POST',
      data: { 
        userId: Number(app.globalData.userId),
        orderStatus:'1'
      },
      success: function (res) {
        console.log(res);
        that.setData({
          payData: res.data
        })
        let orderNumList=[],orderIdList=[]
        for(let i=0;i<that.data.payData.length;i++){
          orderNumList.push(that.data.payData[i].orderNum)
          orderIdList.push(that.data.payData[i].orderId.toString())
        }
        that.setData({
          orderNumList: orderNumList,
          orderIdList: orderIdList
        })
      }
    })
  },

  getSupplePaid(oid){
    let that=this;
    wx.request({
      url: app.globalData.basicUrl + 'user/userOrder/OrderPayList',
      method:'POST',
      data:{
        orderIdList:oid
      },
      success(res){
        console.log(res, '补缴列表')
        that.setData({
          payData: res.data.data
        })
      }
    })
  },

  onCancel: function () {
    var that = this;
    app.onPayCancel(that, 'user/wxPay/localPayment', { 
      // openId:app.globalData.openId,
      userId: wx.getStorageSync('userId'),
      orderNumList: that.data.orderNumList,
      orderIdList:that.data.orderIdList
    })
  },

  onConfirm: function () {
    let that = this;
    app.onPayConfirm(that, 'user/wxPay/createPayment', '&userId=' + wx.getStorageSync('userId') + '&orderNumList=' + that.data.orderNumList.join() + '&orderIdList=' + that.data.orderIdList.join(),'POST')
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if(this.options.oid){
      this.setData({
        oids: this.options.oid
      })
      this.getSupplePaid(this.options.oid)
    } else {
      this.getPayData()
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})